package de.fhaugsburg.games.boardgames.scrabble;

import java.util.List;
import java.util.Vector;

import de.fhaugsburg.games.boardgames.*;
import de.fhaugsburg.games.boardgames.scrabble.scrabbleboard.*;

public class ScrabbleLetterSack extends RandomPool<LetterPiece> {

	private LetterPiece[] letters;
	
	/**
	 * Constructor
	 * Fills Random Pool with Scrabble Letters
	 */
	public ScrabbleLetterSack() {
		this.FillLetterSack();
	}
	
	/**
	 * Fills RandomPool with Scrabble Letters
	 */
	private void FillLetterSack() {
		
		letters = LetterPiece.values();
		
		for (int i=0; i<letters.length; i++) {
			for (int j=0; j<letters[i].getNum(); j++) {
				this.put(letters[i]);
			}
		}
	}
	
	/**
	 * returns seven Letters from sack
	 * @return
	 */
	public List<LetterPiece> take(int numPieces) {
		
		List<LetterPiece> tmpList = new Vector<LetterPiece>(7);
		
		for (int i=0; i < numPieces; i++) {
			if (this.empty()) {break;}
			tmpList.add(this.take());
		}
	return tmpList;
	}
	
	/**
	 * resets the ScrabbleLetterSack
	 */
	public void reset() {
		super.reset();
		this.FillLetterSack();
	}
	

	/**
	 * returns if sack is empty
	 * @return
	 */
	public boolean isEmpty(){
		return (letters.length == 0);
	}
	
	
}
